<template>
  <el-dialog
    :title="id? '编辑页面' : '添加页面' "
    :visible="isShowDialog"
    width="45%"
    @close="btnCancel"
  >
    <el-form ref="addForm" :model="formData" :rules="rules">
      <el-form-item label="标题" prop="title">
        <el-input v-model="formData.title" />
      </el-form-item>
      <el-form-item label="内容" prop="content">
        <!-- <el-input v-model="formData.content" /> -->

        <quill-editor
          v-model="formData.content"
          @blur="$refs.addForm.validateField('content')"
        />
      </el-form-item>
      <el-button type="primary" @click="btnOk">确 定</el-button>
      <el-button @click="btnCancel">取 消</el-button>
    </el-form>

  </el-dialog>

</template>

<script>
import { quillEditor } from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import { addPage, editPage } from '@/api/page'
export default {
  components: {
    quillEditor

  },
  props: {
    isShowDialog: {
      type: Boolean,
      required: true
    },
    id: {
      type: Number,
      required: true
    }
  },

  data() {
    return {
      formData: {
        title: '',
        content: ''
      },
      rules: {
        title: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        content: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ]

      }
    }
  },
  created() {
    // this.getPageList()
  },
  methods: {

    async btnOk() {
      await this.$refs.addForm.validate()
      if (!this.formData.id) {
        await addPage(this.formData)
        this.$message.success('添加页面成功')
      } else {
        await editPage(this.formData, this.id)
      }
      this.$emit('closeDialog')
      this.$emit('reload')
    },
    btnCancel() {
      this.$emit('closeDialog')
      this.formData = {}
    }

  }
}
</script>

<style>

</style>
